package com.huabo.audit.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.hbfk.util.JsonBean;
import com.hbfk.util.ResponseFormat;
import com.huabo.audit.service.AttachmentService;
import com.huabo.audit.service.TblNbsjOperateService;
import com.huabo.audit.service.TblNbsjProjectPreviewService;
import com.huabo.audit.service.TblNbsjProjectService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;

/**
 * 项目资料汇总
 */
@RestController
@Slf4j
@Api(value = "项目资料汇总", tags = { "项目资料汇总接口" })
@RequestMapping(value = "/pjData")
public class NbsjProjectDataController {
	
	@Resource
	public TblNbsjOperateService tblNbsjOperateService;
	
	@Resource
	public AttachmentService attachmentService;
	
	@Resource
	public TblNbsjProjectService tblnbsjProjectService;
	
	@Resource
	public TblNbsjProjectPreviewService tblNbsjProjectPreviewService;
	
	
	/**
	 * 我的任务获取左侧树结构
	 */
	@GetMapping("/myWork/getTree")
	@ApiOperation(value = "我的任务获取左侧树结构")
	public JsonBean myWork_getTree(HttpServletRequest request,
			@ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token) {
		JsonBean jsonBean = null;
		try {
			jsonBean = tblNbsjOperateService.getMyWorkTree(token);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonBean;
	}
	
	
	/**
	 * 任务管理-左侧树
	 */
	@GetMapping("/sjss/getTree")
	@ApiOperation(value = "任务管理-左侧树")
	public JsonBean getTree(HttpServletRequest request,
			@ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
			@ApiParam(name = "nodeId", value = "", required = false) @RequestParam(value = "nodeId", required = false) Integer nodeId,
			@ApiParam(name = "projectId", value = "", required = false) @RequestParam(value = "projectId", required = false) Integer projectId,
			@ApiParam(name = "type", value = "all,my", required = false) @RequestParam(value = "type", required = false) String type) {
		JsonBean jsonBean = null;
		try {
			jsonBean = tblNbsjOperateService.getTree(token, projectId, nodeId, type);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonBean;
	}
	
	/**
	 * 任务管理列表
	 */
	@GetMapping("/sjss/check_list_my_all")
	@ApiOperation(value = "任务管理列表")
	public JsonBean check_list_my_all(HttpServletRequest request,
			@ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
			@ApiParam(name = "pageNumber", value = "分页当前页数", required = false) @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
			@ApiParam(name = "pageSize", value = "每页记录数", required = false) @RequestParam(value = "pageSize", required = false, defaultValue = "15") Integer pageSize,
			@ApiParam(name = "businessType", value = "", required = false) @RequestParam(value = "businessType", required = false) String businessType,
			@ApiParam(name = "targetId", value = "", required = false) @RequestParam(value = "targetId", required = false) Integer targetId) {

		JsonBean jsonBean = null;
		try {
			jsonBean = tblNbsjOperateService.checkAllListMyPageList(token, pageNumber, pageSize,businessType,targetId);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonBean;
	}
	/**
	 * 任务管理-明细
	 */
	@GetMapping("/sjss/check_all_disp")
    @ApiOperation(value = "任务管理-明细")
    public JsonBean check_all_disp(HttpServletRequest request,
    		@ApiParam(name="token",value="登录用户token",required=true) @RequestHeader("token")String token,
    		@ApiParam(name="programid",value="主键",required=true)@RequestParam(value = "programid", required = true) Integer programid) {
    	JsonBean jsonBean = null;
    	try {
			jsonBean = tblNbsjOperateService.checkListMyDetail(token, programid);
		} catch (Exception e) {
			e.printStackTrace();
		}
        return jsonBean;
    }
	
	
	/**
	 * 附件列表
	 */
	@GetMapping("/sjgl/dgfjlist_download")
	@ApiOperation(value = "附件列表")
	public JsonBean dgfjlist_download(HttpServletRequest request,
			@ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
			@ApiParam(name = "attname", value = "附件名称", required = false) @RequestParam(value = "attname", required = false) String attname,
			@ApiParam(name = "pageNumber", value = "分页当前页数", required = false) @RequestParam(value = "pageNumber", required = false, defaultValue = "1") Integer pageNumber,
			@ApiParam(name = "pageSize", value = "每页记录数", required = false) @RequestParam(value = "pageSize", required = false, defaultValue = "15") Integer pageSize) {

		JsonBean jsonBean = null;
		try {
			jsonBean = attachmentService.dgfjlistPageList(token, pageNumber, pageSize,attname);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonBean;
	}
	
	
	/**
	 * 项目查看-项目查看
	 */
	@GetMapping("/sjgl/project_look")
	@ApiOperation(value = "项目查看")
	public JsonBean project_look(HttpServletRequest request,
			@ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
			@ApiParam(name = "projectId", value = "项目id", required = false) @RequestParam(value = "projectId", required = false) Integer projectId) {

		JsonBean jsonBean = null;
		try {
			jsonBean = tblnbsjProjectService.findSSProjectDetail(token,projectId);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonBean;
	}
	
	/**
	 * 项目查看-左侧菜单树
	 */
	@GetMapping("/xmzl/getLiftMenu")
	@ApiOperation(value = "项目查看-左侧菜单树")
    public JsonBean getLiftMenu(HttpServletRequest request,
			@ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token,
			@ApiParam(name = "projectId", value = "项目id", required = false) @RequestParam(value = "projectId", required = false) Integer projectId) {
		JsonBean jsonBean = null;
		try {
			jsonBean = tblNbsjProjectPreviewService.getLiftMenu(token,projectId);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonBean;
    }
	
	/**
	 * 项目归档
	 */
	@GetMapping("/sjss/project_archive_list")
	@ApiOperation(value = "项目归档列表")
	public JsonBean project_archive_list(HttpServletRequest request,
			@ApiParam(name = "token", value = "登录用户token", required = true) @RequestHeader("token") String token) {

		JsonBean jsonBean = null;
		try {
			
			jsonBean = tblNbsjOperateService.pjArchiveMyPageList(token);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonBean;
	}
	
	/**
	 * 项目归档-保存
	 */
	@RequestMapping(value = "/xmgd/save", produces = "application/json; charset=utf-8", method = {RequestMethod.POST})
	@ApiOperation(value = "项目归档-保存")
    public JsonBean save(HttpServletRequest request,
			 @ApiParam(name="token",value="登录用户token",required=false) @RequestHeader("token")String token,
			 @ApiParam(name="selectedData",value="选择业务数据的数组id(用,分隔)",required=false)String selectedData,
			 @ApiParam(name="numPrice",value="实际费用",required=false)Integer numPrice,
			 @ApiParam(name="dateEndTime",value="项目实际结束时间",required=false)String dateEndTime,
			 @ApiParam(name="filCode",value="档案编号",required=false)String filCode,
			 @ApiParam(name="filName",value="档案名称",required=false)String filName)throws Exception{
		JsonBean jsonBean = null;
		try {
			jsonBean = this.tblNbsjOperateService.xmgdSave(token,selectedData,numPrice,dateEndTime,filCode,filName);
		} catch (Exception e) {
			ResponseFormat.retParam(1,1000,e.getMessage());
		}
		return jsonBean;
    }
	

}
